#ifndef AssetManager_H
#define AssetManager_H

#include <QtGui>

//#include "container/Container.h"
#include "Manager.h"
//#include "ResultAttribute.h"
#include "container/IAttribute.h"
#include "container/IResult.h"
#include "container/Result.h"
#include "container/Attribute.h"
#include "container/Question.h"
#include "../TreeNode.h"

class QXmlStreamWriter;


namespace XpsAssets
{

	class Result;
	class Attribute;
	class Response;

	class AssetManager : public QObject
	{
		Q_OBJECT 

	private:
		Manager<Attribute> attributes;
		Manager<Question> questions;
		Manager<Result> results;
		Manager<Response> responses;
		QMap<int, TreeNode*> treeitems;
		QList<unsigned int> linkqueue;

		/// stores the current project filename
		QString	m_Document;
		
	public:
		AssetManager(void);
		~AssetManager(void);

		/// saves current project to xml file
		void save(QString filename, QList<TreeNode*> tree);
		
		/// loads a project from an xml file
		void load(QString filename);

		/// returns the file name of the current document
		QString document() { return m_Document; };

		/// sets the file name of the current document
		void setDocument(QString document = "") { m_Document = document; };

		Question* getQuestion(int id);
		Response* getResponse(int id);
		Attribute* getAttribute(int id);
		Result* getResult(int id);
		TreeNode* getNode(int id);

		int questionCount();
		int resultCount();
		int responseCount(int pos);
		int attributeCount();

		Question* getQuestionAt(int pos);
		Attribute* getAttributeAt(int pos);

	signals:
		/// emitted if a file is successfully loaded
		void sAssetsLoaded();

		/// emitted if a file is successfully saved
		void sAssetsSaved();

		/// emitted if a new attribute is created
		void sNewAttribute(int);
		
		/// emitted if a new question is created
		void sNewQuestion(int);

		/// emitted if a new result is created
		void sNewResult(int);

		/// emitted if a new response is created	
		void sNewResponse(int, int);

		/// emitted if a new response attribute is created	
		void sNewResponseAttribute(int, int);

		/// emitted if a new response attribute is removed
		void sResponseAttributeRemoved(int, int);

		/// emitted for each treenode loaded
		void sNewTreeNode(int);

		// emitted for each link loaded
		void sNewLink(int, int, int);

		/// emitted if a qustion is removed
		void sQuestionRemoved(int);

		/// emitted if a result is removed
		void sResultRemoved(int);

		/// emitted if a result is removed
		void sAttributeRemoved(int);

		/// emitted if a qustion is removed
		void sResponseRemoved(int, int);

	public slots:
		int createAttribute();
		int createQuestion();
		int createResult();
		int createResponse(int qid);
		int createResponseAttribute(int rid, int aid);
		
		void deleteResponseAttribute(int rid, int aid);
		void deleteAttribute(int id);
		void deleteResult(int id);
		void deleteQuestion(int id);
		void deleteResponse(int qid, int rid);
		void cleanUp();
	};

}

#endif